package com.hyg.lib_music.presenter;

import android.content.Context;

import com.hyg.lib_common.DataModel.Music.MusicDocData;
import com.hyg.lib_common.DataModel.Music.response.DocListResponse;
import com.hyg.lib_music.network.NetManager;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Single;

public class MusicDocListPresenter implements MusicDocListContract.Presenter{

    private MusicDocListContract.View mFragment;
    private CloseableRxServiceExecutor executor;

    @Inject
    public MusicDocListPresenter(Context context,
                                 CloseableRxServiceExecutor executor) {
        this.executor = executor;
    }

    @Override
    public void setContractView(MusicDocListContract.View fragment) {
        mFragment = fragment;
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDestroy() {
    }

    /**
     * 分类列表
     *
     * @return
     */
    public Single<DocListResponse> docListRequest(int cateId) {

        return Single.create(emitter -> emitter.onSuccess(NetManager.sharedManager().docListRequest(cateId)));

    }

    @Override
    public void getDocList(int cateId){

        executor.execute(

                this.docListRequest(cateId),
                response -> {
                    if (response.code == 200)
                    {
                        List<MusicDocData> data= response.data;
                        mFragment.setDocListData(data);
                    }else {
                        //失败逻辑
                    }
                },
                error -> {
//                    Logger.d(error);
                });
    }

}